package com.cac.demo.service.wmsitemtransaction;

import com.cac.demo.dao.wmsitemtransaction.WmsItemTransactionDao;
import com.cac.demo.entity.wmsitemtransaction.WmsItemTransactionDTO;
import com.cac.demo.util.adapter.DaoException;
import com.cac.demo.util.adapter.QueryReqBean;
import com.cac.demo.util.adapter.QueryRespBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class WmsItemTransactionService {

    @Autowired
    private WmsItemTransactionDao wmsItemTransactionDao;


    //库存管理流水查询
    @Transactional
    public QueryRespBean<WmsItemTransactionDTO> searchParamsByBarcodeAM(QueryReqBean<WmsItemTransactionDTO> queryReqBean, String orderBy, String Keywords, Date startTime, Date endTime,
                                                                        String itemCode) {
        QueryRespBean<WmsItemTransactionDTO> queryRespBean =new QueryRespBean<>();
        try {
            PageHelper.startPage(queryReqBean.getPageParameter());
            WmsItemTransactionDTO searchParams = queryReqBean.getSearchParams();
            Page<WmsItemTransactionDTO> dataList = wmsItemTransactionDao.searchAllByItem(searchParams,orderBy,Keywords,startTime,endTime,itemCode);
            queryRespBean.setResult(dataList);
            return queryRespBean;
        }catch (Exception e) {
            throw new DaoException(e.getMessage(), e);
        }
    }

    //出入库流水查询
    @Transactional
    public PageInfo outInFlowQuery(int startPage, int pageSize, HashMap queryParam){
        com.github.pagehelper.PageHelper.startPage(startPage,pageSize);
        List<HashMap> data = wmsItemTransactionDao.outInFlowQuery(queryParam);
        PageInfo pageInfo = new PageInfo(data);
        return pageInfo;
    }

}
